package qiniuStorage

import (
	"cat-collage-backend/internal/config"
	"github.com/qiniu/go-sdk/v7/auth"
	qiniuStorage "github.com/qiniu/go-sdk/v7/storage"
)

var QiniuConfig qiniuStorage.Config

func InitStorage(cfg *config.Config) {
	// 初始化七牛云存储
	accessKey := cfg.Upload.QiniuAccessKey
	secretKey := cfg.Upload.QiniuSecretKey
	bucket := cfg.Upload.QiniuBucket
	zone := cfg.Upload.QiniuZone
	QiniuConfig.Region = &qiniuStorage.ZoneXinjiapo
	QiniuConfig.UseCdnDomains = false
	putPolicy := qiniuStorage.PutPolicy{
		Scope: bucket,
	}
	mac := auth.New(accessKey, secretKey)
	upToken := putPolicy.UploadToken(mac)
	cfg.Upload.QiniuUpToken = upToken
	cfg.Upload.QiniuMac = mac
	cfg.Upload.QiniuBucket = bucket
	cfg.Upload.QiniuZone = zone
	cfg.Upload.QiniuAccessKey = accessKey
	cfg.Upload.QiniuSecretKey = secretKey
}
